package com.mybatis.generator;

import com.mybatis.generator.core.Context;
import com.mybatis.generator.core.FreemarkerUtils;
import com.mybatis.generator.core.JavaBeanUtils;
import com.mybatis.generator.core.Table;

public class DtoGenerator {

	private static final String TEMPLATE_NAME = "freemaker-dto";

	public static void process(Context ctx, Table table) throws Exception {
		if(table.getDto() == null){
			return;
		}
		StringBuilder sb = new StringBuilder(ctx.getDto());
		sb.append(JavaBeanUtils.splitString(table.getDto().getPackageName()));
		sb.append("/");
		sb.append(table.getDto().getName()).append(".java");
		FreemarkerUtils.write(sb.toString(),
				FreemarkerUtils.process(TEMPLATE_NAME, table));
	}
	
}
